﻿using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Crm;

namespace Konekcija.Core.Reporting.Mappings.Crm
{
    public class AccountMap : ClassMap<Account>
    {
        public AccountMap()
        {
            Schema("crm");
            Table("Accounts");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.Name).Nullable();
            Map(x => x.Password).Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.AccountType).Nullable();

            HasManyToMany(x => x.Products)
                .LazyLoad()
                .Inverse()
                .ParentKeyColumn("AccountId")
                .ChildKeyColumn("ProductId")
                .Table("crm.AccountsToProducts");

            HasMany(x => x.DeveloperApiKeys)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("AccountId");
        }
    }
}